<?php
class NavListWidget extends CWidget
{
    public function init()
    {
        parent::init();
    }

    public function run()
    {
        $category = array();
        $menus = array();
        //用户权限
        $id = Yii::app()->user->getId();
        $user_info  = Manager::model()->getArrById($id);
        if (empty($user_info)) {
            echo 'error : empty user_info';
            exit;
        }
        if(empty($user_info['sp'])){
            $user_info['sp'] = array();
        }
        $name = Yii::app()->session->get('adminName');
        if ($this->getController()->nav_type == 'cgm') {
            if ($name == 'admin' || in_array('user/list', $user_info['sp']) || in_array('feedback/list',$user_info['sp'])|| in_array('user/carrylist', $user_info['sp']) ) {
                $category['customer'] = array('用户管理', 'fa-user');
                if($name == 'admin' || in_array('user/list',$user_info['sp'])){
                    $menus['customer'][] = array('用户列表', $this->getController()->createUrl('user/list'));
                }
                if($name == 'admin' || in_array('feedback/list',$user_info['sp'])){
                    $menus['customer'][] = array('用户留言', $this->getController()->createUrl('feedback/list/type/2'));
                }

            }

            if ($name == 'admin' || in_array('system/setting', $user_info['sp']) || in_array('system/ship', $user_info['sp']) || in_array('system/command', $user_info['sp']) || in_array('system/shipfee', $user_info['sp'])) {
                $category['system'] = array('系统管理', 'fa-cog');
                if($name == 'admin' || in_array('system/setting',$user_info['sp'])){
                    $menus['system'][] = array('系统设置', $this->getController()->createUrl('system/setting'));
                }
                // if($name == 'admin' || in_array('system/param',$user_info['sp'])){
                //     $menus['system'][] = array('参数配置', $this->getController()->createUrl('system/param'));
                // }
                // if($name == 'admin' || in_array('system/article',$user_info['sp'])){
                //     $menus['system'][] = array('文章配置', $this->getController()->createUrl('system/article'));
                // }
            }
            if ($name == 'admin' || in_array('package/index', $user_info['sp'])) {
                $category['package'] = array('安装包管理', 'fa-cog');
                $menus['package'][] = array('安装包管理', $this->getController()->createUrl('package/index'));
            }
            if ($name == 'admin') {
                $category['rules'] = array('权限管理', 'fa-cog');
                $menus['rules'][] = array('管理员', $this->getController()->createUrl('manager/'));
                $menus['rules'][] = array('操作日志', $this->getController()->createUrl('option/index'));
            }

        } 
        $c = $this->controller->id;
        $a = $this->controller->action->id;
        $url = Yii::app()->request->getUrl();
        $ac = '';
        $am = '';
        $show_page = false;
        foreach ($menus as $ck => $ms) {
            foreach ($ms as $lk => $m) {
                if ($url == $m[1]) {
                    $menus[$ck][$lk]['active'] = 'active';
                    $category[$ck]['active'] = 'active';
                    $show_page = true;
                }
                if ('/admin/'.$c.'/'.$a == $m[1]) {
                    $ac = $ck;
                    $am = '/admin/'.$c.'/'.$a;
                }
            }
        }
        $this->render("NavList", compact('category', 'menus', 'c', 'a', 'ac', 'am', 'show_page'));
    }

}
?>
